function request(method, url, data) {
    // const baseUrl = 'https://fl.flya.top:30946'
    const baseUrl='https://hole.flya.top:32079'
    // const baseUrl ='http://test.flya.top'
    const GET = 'GET';
    const POST = 'POST';
    const PUT = 'PUT';
    const FORM = 'FORM';
    const DELETE = 'DELETE';
    const token = wx.getStorageSync('token') || ''
    let ajaxTimes = 0;
    let header = {
        'content-type': 'application/json',
        Authorization: token
    };
    ajaxTimes++;
    //显示加载中 效果
    wx.showLoading({
        title: '加载中',
        mask: true
    })


    return new Promise(function (resolve, reject) {

        wx.request({
            // responseType: 'arraybuffer',
            url: baseUrl + url,
            method: method,
            data: method === POST ? JSON.stringify(data) : data,
            header: header,
            //超时时间
            timeout: 10000,
            success(res) {


                if (res.statusCode == 200) {
                    resolve(res);

                } else if (res.statusCode == 401) {
                    if (res.data.statusCode == 40301) {
                        wx.showToast({
                            title: '登录过期，请重新登录',
                            icon: 'none',
                            duration: 10000
                        })
                    }

                } else {
                    resolve(res);
                }
            },
            fail(err) {
                //请求失败
                console.log(err)
                let msg = ''
                if (err.errMsg == 'request:fail ') {
                    msg = '网络异常'
                }else if(err.errMsg == 'request:fail timeout '){
                    msg = '请求超时'
                }else{
                    msg=err.errMsg
                }
                //弹窗
                wx.showToast({
                    title: msg,
                    icon: 'none',
                    duration: 3000
                })

                reject(err)
            },

            complete: () => {
                ajaxTimes--
                //关闭正在等待的图标
                if (ajaxTimes === 0) {
                    wx.hideLoading()
                }

            }

        })
    })
}

function request_music(method, url, data) {
    const baseUrl = 'https://music.flya.top'
    // const baseUrl='http://127.0.0.1:8089'
    // const baseUrl ='http://59.172.226.5'
    const GET = 'GET';
    const POST = 'POST';
    const PUT = 'PUT';
    const FORM = 'FORM';
    const DELETE = 'DELETE';
    const token = wx.getStorageSync('token') || ''
    let ajaxTimes = 0;
    let header = {
        'content-type': 'application/json',
        Authorization: token

    };
    ajaxTimes++;
    //显示加载中 效果
    wx.showLoading({
        title: '加载中',
        mask: true
    })


    return new Promise(function (resolve, reject) {

        wx.request({
            // responseType: 'arraybuffer',
            url: baseUrl + url,
            method: method,
            data: method === POST ? JSON.stringify(data) : data,
            header: header,
            //超时时间
            timeout: 10000,
            success(res) {


                if (res.statusCode == 200) {
                    resolve(res);

                } else if (res.statusCode == 401) {
                    if (res.data.statusCode == 40301) {
                        wx.showToast({
                            title: '登录过期，请重新登录',
                            icon: 'none',
                            duration: 10000
                        })
                    }

                } else {
                    resolve(res);
                }
            },
            fail(err) {
                //请求失败
                console.log(err)
                let msg = ''
                if (err.errMsg == 'request:fail ') {
                    msg = '网络异常'
                }else if(err.errMsg == 'request:fail timeout '){
                    msg = '请求超时'
                }else{
                    msg=err.errMsg
                }
                //弹窗
                wx.showToast({
                    title: msg,
                    icon: 'none',
                    duration: 3000
                })

                reject(err)
            },

            complete: () => {
                ajaxTimes--
                //关闭正在等待的图标
                if (ajaxTimes === 0) {
                    wx.hideLoading()
                }

            }

        })
    })
}



//衔接上面代码

export const server = request;
export const server_music = request_music;